//
//  ZHTQPresentationController.swift
//  ZHTQWeibo
//
//  Created by ZHTQ on 2018/9/15.
//  Copyright © 2018年 ZHTQ. All rights reserved.
//

import UIKit

class ZHTQPresentationController: UIPresentationController {

    ///显示菜单试图的尺寸
    var presentedViewFrame = CGRect.zero
    
    ///改变presentVC的尺寸
    override func containerViewWillLayoutSubviews() {
        
        
        //1.设置试图的 尺寸
        presentedView?.frame = presentedViewFrame
        
        //2.监听蒙板按钮点击
        coverView.addTarget(self, action: #selector(coverViewDidClick), for: UIControlEvents.touchUpInside)
        //3.添加蒙板
        containerView?.insertSubview(coverView, at: 0)
    }
    
    //MARK:- 内部控制
    ///蒙板按钮点击
    @objc private func coverViewDidClick() {
        //diss 控制器
        presentedViewController.dismiss(animated: true, completion: nil)
    }
    
    //MARK:- 懒加载
    private lazy var coverView: UIButton = {
        () -> UIButton in
        //创建按钮设置尺寸
        let btn = UIButton()
        btn.frame = UIScreen.main.bounds
        btn.backgroundColor = UIColor.clear
        return btn
    }()
}
